# Contributor: Bennett Goble <nivardus@gmail.com>
# Contributor: Axel Ulrich <ulrich.axel@gmail.com>
# Maintainer:
pkgname=h2o
pkgver=2.2.6
pkgrel=8
pkgdesc="An optimized HTTP/1, HTTP/2 server written in C"
url="https://h2o.examp1e.net"
arch="all !s390x"
depends="perl openssl"
license="MIT"
checkdepends="
	nodejs
	perl-cgi
	perl-cookie-baker
	perl-fcgi
	perl-fcgi-procmanager
	perl-hash-multivalue
	perl-http-entity-parser
	perl-http-headers-fast
	perl-json
	perl-lwp-protocol-https
	perl-path-tiny
	perl-plack
	perl-protocol-http2
	perl-scope-guard
	perl-starlet
	perl-test-exception
	perl-test-harness-utils
	perl-test-requires
	perl-test-simple
	perl-test-tcp
	wget
	"
makedepends="
	bison
	cmake
	libuv-dev
	openssl1.1-compat-dev
	ruby-dev
	wslay-dev
	yaml-dev
	zlib-dev
	"
install="$pkgname.pre-install"
subpackages="$pkgname-dev $pkgname-doc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/h2o/h2o/archive/v$pkgver.tar.gz
	h2o.conf
	h2o.initd
	h2o.logrotate
	missingsubmodules.patch
	backslashinterpreationintests.patch
	disabletls13intls12tests.patch
	largeheadertest.patch
	proxysessionresumption.patch
	sessiontickettest.patch
	cannotlocatetutilpm.patch
	increasewaitforserverstartintests.patch
	fix-ruby-3.0-compat.patch
	"
options="!check"  # various tests fails

[ "$CARCH" = "riscv64" ] && options="$options textrels"

# secfixes:
#   2.2.6-r0:
#     - CVE-2019-9512
#     - CVE-2019-9514
#     - CVE-2019-9515

build() {
	cmake -B build \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_SHARED_LIBS=ON \
		-DCMAKE_INSTALL_LIBDIR=/usr/lib \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DWITH_MRUBY=ON
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir/etc/init.d/$pkgname"

	install -m644 -D "$srcdir"/$pkgname.logrotate \
		"$pkgdir"/etc/logrotate.d/$pkgname

	install -m644 -D "$srcdir"/$pkgname.conf \
		"$pkgdir"/etc/$pkgname.conf

	install -m644 -D "$builddir"/examples/doc_root/index.html \
		"$pkgdir"/var/www/index.html

	install -m700 -d "$pkgdir"/var/log/$pkgname
}

sha512sums="
f2f28905c01782a0432c9dfdb2f21054e0a4741ac4c5f26802d4b439d0172840aa215aba5dc7c9af62275dcc24de105674a3819384dc38246e43ce3e8263eb20  h2o-2.2.6.tar.gz
444f55c3eaae1f349223036086e45c983ea8be89e793068537ec25488c4065174bc509d0987ddc65a0357cb8acfec272e90d13ea7cdadf9cf112953d857aa574  h2o.conf
e93e66a6b00b1bff94e37489c5fdf99d9d657adc63975ec54be30f8da23dafe7d7389f02a6452ed819efc9d8398aa716782a7fd6d8509621a975ed954b73bef9  h2o.initd
3d2c9e36c48cbb974d0691e4af8e9eb8f13e3bebb98a30417cdc87e76a4b5cddc4e4f665ebea26b95174287b95d002fdc3363f30ffcf15247fcd0530fe1abfcc  h2o.logrotate
c03ceeea23a545b948815aeb48872dbac388665f0c79c643e7fa17695580c71260b2227058fe60702d052536e8bdb4d8104d430557ec0c3c4515ed132db7a4a8  missingsubmodules.patch
cd62b93041f2f9407d3aa82c924aa13a3f38330a3557c230c47f30eb3d8bbb90db95cdd2ff1e8248eadcae711c90d0e33caa221ede46015df92c3fe4148a6f21  backslashinterpreationintests.patch
28c5a3a8f64391f317c90f826a488e513b25ad3e7c5febffc0f3a0323b361e4b2900d9dd5e542754b0083c30f68f270eb3b17a8b23ad3f43e4b28feb260ad9eb  disabletls13intls12tests.patch
a8b2edff9da782319682ecbf62b93090eedc5503236a7106d0313429b157ec091ddbeb9b8f9f91567ae712a4f2c082b9ba8f84d890b72b54c161c0c4e1cab0ef  largeheadertest.patch
a5df628f200475f5db6eb9d1714e955cd33c2de3081ee5f770929833a4cb9e5030fe338c23bcfb516235c2036c6e6452bb52447da0c3d69e3ea8de8bfa00f420  proxysessionresumption.patch
9304ea3ebb74eb66f3d8c8facfc8a08366cb35ac8f5ee8090f59202abd13842d4a4565b5cbfcfff3110473a03bb9ff00b0f74311b450113675f0cb6d6b759d90  sessiontickettest.patch
848b9d20221c2d55b034bd3b9943100fd82f3e32a6032e126868471f9e18f60a9d94bc9024890e4af7ee8ffd6308cc1beb001e3052cb938b14280d331493307b  cannotlocatetutilpm.patch
26c4f34bdcb82cdca00b81e8c3223a1c517f912f433e99ae4a9aa16481db2cd23fc77f65773932f8c6e30cb5e34d5d37e0e7a022518a6a13db75d8e16fee2ab4  increasewaitforserverstartintests.patch
8d5f6f6232fba5b36f4bdba2d3c815add434b5f1d063241639cf963b5caea53ff9d459b60cd391d6b043fa17ca022e5bde7a04aec60185ff791d167d518eba74  fix-ruby-3.0-compat.patch
"
